<template>
    <div class="page">
        <nav-bar>
            <!-- 具名插槽 -->
            <template #left>
                <div class="lefts">
                    <van-icon name="arrow-left" @click="$router.go(-1)"></van-icon>
                </div>
            </template>
            <template #center>
                <div>
                    选择地址
                </div>
            </template>
        </nav-bar>
        <div>
            <div v-if="addressList.length!=0">
                <van-address-list v-model="addressList[0].id" :list="addressList"  default-tag-text="默认" @add='add'/>
            </div>
        </div>
    </div>
</template>
<script>
import { getAdressList } from '@/api/login'
export default {
    data() {
        return {
            addressList: []
        }
    },
    async created() {
        let res = await getAdressList(this.$store.state.userId);
        console.log(res)
        // this.addressList = res.data;
        res.data.forEach(item=>{
            let obj = {
                id:item.id,
                name:item.name,
                tel:item.phone,
                address:item.address
            }
            this.addressList.push(obj)
        })
    },
    methods:{
        add(){
            this.$router.push({
                path:"/add/address"
            })
        }
    }
}
</script>